home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / comm / comm2 / ctsrc701.lha / netrcv.c < prev    next >
C/C++ Source or Header  |  1996-12-28  |  22KB  |  909 lines

  1. /*
  2. *       netrcv.c
  3. *
  4. *      Networking functions for reception.
  5. */
  6. /*
  7. *       history
  8. *
  9. * 86Aug20 HAW  History not maintained due to space problems.
  10. */
  11. #include "ctdl.h"
  12. /*
  13. *       Contents
  14. *
  15. * called()    Handle being called.
  16. * rcvStuff()    Manage receiving stuff.
  17. * netPwd()    Check password.
  18. * doResults()   Post-process results.
  19. * getId()     Get nodeId and nodeName from caller.
  20. * getNextCommand()  Get next command.
  21. * grabCommand()   Extract network cmds from buffer.
  22. * reply()     Sends a reply to caller.
  23. * reqReversal()   Handle role reversal.
  24. * reqCheckMail()    Check incoming mail.
  25. * targetCheck()   Check for existence of recipients.
  26. * CheckRecipient()  work fn for above.
  27. * doNetRooms()    Manage integrating incoming messages.
  28. * IntegrateRoom()   work fn for above.
  29. * ReadNetRoomFile() work fn for above.
  30. * getMail()   Handle incoming mail.
  31. * reqSendFile()   Receive a sent file.
  32. * netFileReq()    Senda a requested file.
  33. * netRRReq()    Handle room sharing.
  34. * recNetMessages()  Receive net messages.
  35. * UpdateRecoveryFile()  Updates the network recovery file.
  36. *   RoomRoutable()    Is this room routable?
  37. * IsRoomRoutable()  Is this room routable?
  38. * netMultiSend()    Send multiple files.
  39. * RecoverNetwork()  Recover from network disaster.
  40. */
  41. extern char logNetResults;
  42. char        netDebug = FALSE;
  43. char    processMail;
  44. char    PosId;
  45. char    *AssignAddress = NULL;
  46. #define RECOVERABLE 1
  47. extern char   *SR_Sent;
  48. extern FILE   *netLog, *netMisc;
  49. extern AN_UNSIGNED      RecBuf[];
  50. extern int    counter;
  51. extern int    callSlot;
  52. extern char   checkNegMail;
  53. extern char   inReceive;
  54. extern label    normed, callerName, callerId;
  55. extern char   RouteMailForHere;
  56. extern char   *LOC_NET, *NON_LOC_NET;
  57. char    normId(), getNetMessage();
  58. char    callOut();
  59. AN_UNSIGNED      inp();
  60. char *netRoomTemplate = "room%d.$$$";
  61. char *SharingRefusal[] =
  62.   {
  63.   "'%s' does not exist",
  64.   "'%s' is not a networking room",
  65.   "'%s' is not networking with you",
  66.   "No can do for '%s'",
  67.  
  68.   };
  69. extern char  RecMassTransfer;
  70. extern CONFIG    cfg;   /* Lots an lots of variables    */
  71. extern logBuffer logBuf;  /* Person buffer    */
  72. extern logBuffer logTmp;  /* Person buffer    */
  73. extern aRoom     roomBuf; /* Room buffer    */
  74. extern rTable    *roomTab;
  75. extern MessageBuffer   msgBuf;
  76. extern NetBuffer netBuf;
  77. extern NetTable  *netTab;
  78. extern int       thisNet;
  79. extern char      onConsole;
  80. extern char      loggedIn;  /* Is we logged in?   */
  81. extern char      outFlag; /* Output flag    */
  82. extern char      haveCarrier; /* Do we still got carrier?     */
  83. extern char      modStat; /* Needed so we don't die       */
  84. extern char      WCError;
  85. extern int       thisRoom;
  86. extern int       thisLog;
  87. extern char  *APPEND_TEXT, *WRITE_TEXT, *READ_TEXT;
  88. extern char  *R_SH_MARK, *NON_LOC_NET, *LOC_NET;
  89. extern long char_in, char_out, start_time;
  90.  
  91. /*
  92. * called()
  93. *
  94. * We've been called, so let's handle it.
  95. */
  96. void called()
  97.   {
  98.   ITL_InitCall();   /* Initialize the ITL layer */
  99.   memset(SR_Sent, 0, SHARED_ROOMS);
  100.   inReceive = TRUE;
  101.   RecMassTransfer = FALSE;
  102.   SpecialMessage("Status:Net Carrier");
  103.   if( logNetResults || netDebug )splitF(netLog, "Carrier %s\n", Current_Time());
  104.   processMail = checkNegMail = FALSE;
  105.   if (!called_stabilize())
  106.     {
  107.     if (cfg.BoolFlags.debug)splitF(netLog," Not Stabilized...\n");
  108.     return ;
  109.  
  110.     };
  111.   if( logNetResults && netDebug )splitF(netLog, "Stabilized\n");
  112.   SpecialMessage("Status:Net Session");
  113.   char_in = char_out = 0;
  114.   start_time = Set_Timer(0);       /* initialize time of day */
  115.   getId();
  116.   if (!haveCarrier) return;
  117.   rcvStuff(FALSE);
  118.   splitF(netLog, "Finished with %s @%s\n",  callerName, Current_Time());
  119.   Compute_Data(callerName);
  120.   pause(20);
  121.   killConnection();
  122.   doResults();
  123.   SpecialMessage("Status:Net Completed");
  124.  
  125.   }
  126. /*
  127. * rcvStuff()
  128. *
  129. * This function manages receiving stuff.
  130. */
  131. void rcvStuff(char reversed)
  132.   {
  133.   label     tempNm;
  134.   struct cmd_data cmds;
  135.   PosId = (callSlot == ERROR) ? FALSE : (netBuf.OurPwd[0] == 0 || (reversed && netBuf.nbflags.Stadel));
  136.   RouteMailForHere = FALSE;
  137.   do
  138.     {
  139.     getNextCommand(&cmds);
  140.     switch (cmds.command)
  141.       {
  142.       case HANGUP:          break;
  143.       case NORMAL_MAIL:    getMail();     break;
  144.       case A_FILE_REQ:
  145.       case R_FILE_REQ:     netFileReq(&cmds);   break;
  146.       case NET_ROOM:       netRRReq(&cmds, FALSE);  break;
  147.       case ROLE_REVERSAL:  reqReversal(reversed);   break;
  148.       case CHECK_MAIL:     reqCheckMail();    break;
  149.       case SEND_FILE:      reqSendFile(&cmds);    break;
  150.       case NET_ROUTE_ROOM: netRRReq(&cmds, TRUE);   break;
  151.       case SYS_NET_PWD:    netPwd(&cmds);     break;
  152.       case ITL_PROTOCOL:   ITL_rec_optimize(&cmds);       break;
  153.       case ITL_COMPACT:    ITL_RecCompact(&cmds);   break;
  154.       case ROUTE_MAIL:     netRouteMail(&cmds);   break;
  155.       case FAST_MSGS:  netFastTran(&cmds);    break;
  156.       default:
  157.       sprintf(tempNm, "'%d' unknown.", cmds.command);
  158.       reply(BAD, tempNm);   break;
  159.  
  160.       }
  161.  
  162.     }
  163.   while (gotCarrier() && cmds.command != HANGUP);
  164.  
  165.   }
  166. /*
  167. * netPwd()
  168. *
  169. * Check out the password sent to us, set flags appropriately.
  170. */
  171. void netPwd(struct cmd_data *cmds)
  172.   {
  173.   if (callSlot != ERROR)
  174.     {
  175.     PosId = !strCmpU(cmds->fields[0], netBuf.OurPwd);
  176.     if (!PosId)
  177.       {
  178.       if( logNetResults )splitF(netLog, "Bad pwd: -%s-\n", cmds->fields[0]);
  179.       sPrintf(msgBuf.mbtext, "%s sent bad password -%s-.",
  180.       callerName, cmds->fields[0]);
  181.       netResult(msgBuf.mbtext);
  182.  
  183.       }
  184.  
  185.     }
  186.   reply(GOOD, "");
  187.  
  188.   }
  189. /*
  190. * doResults()
  191. *
  192. * This function processes the results of receiving thingies and such.
  193. */
  194. void doResults()
  195.   {
  196.   extern SListBase DomainMap;
  197.   void HandleExistingDomain();
  198.   int i;
  199.   label temp;
  200.   extern int RMcount;
  201.   DisableModem(TRUE);
  202.   InitVortexing();    /* handles all mail for here */
  203.   if (processMail)
  204.     {
  205.     if (AddNetMsgs("tempmail.$$$", inMail, 2, MAILROOM, TRUE) == ERROR)
  206.     no_good("No mail file for %s?", TRUE);
  207.  
  208.     }
  209.   if (RouteMailForHere)
  210.     {
  211.     for (i = 0; ; i++)
  212.       {
  213.       sPrintf(temp, "rmail.%d", i);
  214.       if (AddNetMsgs(temp, inRouteMail, 2, MAILROOM, TRUE) == ERROR)
  215.       break;
  216.  
  217.       }
  218.     RMcount = 0;
  219.  
  220.     }
  221.   FinVortexing();   /* finish handling mail */
  222.   if (callSlot == ERROR)
  223.     {
  224.     /* If didn't know this node, don't      */
  225.     EnableModem(TRUE);
  226.     return ;  /* bother with anything else  */
  227.  
  228.     }
  229.   if (checkNegMail) readNegMail(TRUE);
  230.   ReadFastFiles();    /* messages transferred in one big arc */
  231.   doNetRooms();
  232.   AdjustRoute();
  233.   netBuf.nbLastConnect = CurAbsolute();
  234.   putNet(thisNet, &netBuf);
  235.   UpdVirtStuff(); /* Just in case. */
  236.   RunList(&DomainMap, HandleExistingDomain);
  237.   RationalizeDomains(); /* again just in case ... */
  238.   EnableModem(TRUE);
  239.  
  240.   }
  241. /*
  242. * getId()
  243. *
  244. * This gets nodeId and nodeName from caller.
  245. */
  246. void getId()
  247.   {
  248.   char *secRunner;
  249.   #ifdef NEED_THIS_DATA
  250.   SYS_FILE fn;
  251.   #endif
  252.   int i;
  253.   extern long byteRate;
  254.   extern char *APPEND_ANY;
  255.   if (!haveCarrier) return;
  256.   ITL_Receive(NULL, FALSE, TRUE, putFLChar, fclose);
  257.   if (!gotCarrier())
  258.     {
  259.     return ;
  260.  
  261.     }
  262.   strncpy(callerId, RecBuf, NAMESIZE - 1);
  263.   secRunner = RecBuf;
  264.   while (*secRunner != 0) secRunner++;
  265.   secRunner++;
  266.   strncpy(callerName, secRunner, NAMESIZE - 1);
  267.   normId(callerId, normed);
  268.   if (strLen(callerName) == 0 || strLen(callerId) == 0)
  269.     {
  270.     if( logNetResults )splitF(netLog, "getId invalid data, dropping connection.\n\n");
  271.     killConnection();
  272.     #ifdef NEED_THIS_DATA
  273.     makeSysName(fn, "getid.sys", &cfg.netArea);
  274.     if ((upfd = safeopen(fn, APPEND_ANY)) != NULL)
  275.       {
  276.       fwrite(RecBuf, SECTSIZE, 1, upfd);
  277.       fclose(upfd);
  278.  
  279.       }
  280.     #endif
  281.  
  282.     }
  283.   if ((callSlot = searchNet(normed, &netBuf)) == ERROR)
  284.     {
  285.     sPrintf(msgBuf.mbtext, "New caller: %s (%s)", callerName, callerId);
  286.     netResult(msgBuf.mbtext);
  287.  
  288.     }
  289.   else
  290.     {
  291.     for (i = 0; i < SHARED_ROOMS; i++)
  292.     resetNeedsProcessing(i);
  293.     putNet(callSlot, &netBuf);
  294.  
  295.     }
  296.   if( logNetResults)splitF(netLog, "%s (%s) @ %ld\n", callerName, callerId, byteRate * 10L);
  297.  
  298.   }
  299. /*
  300. * getNextCommand()
  301. *
  302. * This gets next command (facility request) from the caller.
  303. */
  304. void getNextCommand(struct cmd_data *cmds)
  305.   {
  306.   zero_struct(*cmds);
  307.   ITL_Receive(NULL, FALSE, TRUE, putFLChar, fclose);
  308.   if (!gotCarrier())
  309.     {
  310.     return ;
  311.  
  312.     }
  313.   grabCommand(cmds, RecBuf);
  314.   }
  315. /*
  316. * grabCommand()
  317. *
  318. * This pulls network cmds out of the specified buffer.
  319. */
  320. void grabCommand(struct cmd_data *cmds, char *sect)
  321.   {
  322.   int fcount = 0;
  323.   cmds->command = sect[0];
  324.   sect++;
  325.   while (sect[0] > 0 && fcount < 4)
  326.     {
  327.     strncpy(cmds->fields[fcount], sect, NAMESIZE - 1);
  328.     cmds->fields[fcount][NAMESIZE - 1] = 0;
  329.     fcount++;
  330.     while (*sect != 0) sect++;
  331.     sect++;
  332.  
  333.     }
  334.   }
  335. /*
  336. * reply()
  337. *
  338. * This sends a full reply to the caller's request.
  339. */
  340. void reply(char state, char *reason)
  341.   {
  342.   if (!ITL_Send(STARTUP))
  343.     {
  344.     no_good("Couldn't send reply to %s!", TRUE);
  345.     return;
  346.  
  347.     }
  348.   sendITLchar(state);
  349.   if (state == BAD)
  350.     {
  351.     mTrPrintf("%s", reason);
  352.     if (cfg.BoolFlags.debug) splitF(netLog, "Replying BAD: %s\n", reason);
  353.  
  354.     }
  355.   sendITLchar(0);
  356.   ITL_Send(FINISH);
  357.  
  358.   }
  359. /*
  360. * reqReversal()
  361. *
  362. * This handles the role reversal command.
  363. */
  364. void reqReversal(char reversed)
  365.   {
  366.   if ( logNetResults && netDebug ) splitF(netLog, "Role reversal\n");
  367.   if (reversed)
  368.     {
  369.     reply(BAD, "Synch error on Reversal!");
  370.     return ;
  371.  
  372.     }
  373.   reply(GOOD, "");
  374.   if (callSlot == ERROR)      /* Forces a "null" role reversal  */
  375.   zero_struct(netBuf.nbflags);
  376.   sendStuff(TRUE, PosId);
  377.  
  378.   }
  379. /*
  380. * reqCheckMail()
  381. *
  382. * This checks incoming mail and does negative acks where appropriate.
  383. */
  384. void reqCheckMail()
  385.   {
  386.   if( logNetResults && netDebug )splitF(netLog, "checking Mail\n");
  387.   if (!processMail)
  388.     {
  389.     reply(BAD, "No mail to check!");
  390.     return ;
  391.  
  392.     }
  393.   reply(GOOD, "");
  394.   if (ITL_Send(STARTUP))
  395.     {
  396.     AddNetMsgs("tempmail.$$$", targetCheck, FALSE, MAILROOM, TRUE);
  397.     sendITLchar(NO_ERROR);
  398.     ITL_Send(FINISH);
  399.  
  400.     }
  401.  
  402.   }
  403. /*
  404. * targetCheck()
  405. *
  406. * This checks for existence of recipients.
  407. */
  408. void targetCheck()
  409.   {
  410.   if (HasOverrides(&msgBuf))
  411.     {
  412.     RunList(&msgBuf.mbOverride, CheckRecipient);
  413.  
  414.     }
  415.   else
  416.     {
  417.     CheckRecipient(msgBuf.mbto);
  418.  
  419.     }
  420.  
  421.   }
  422. /*
  423. * CheckRecipient()
  424. *
  425. * This will check to see if the recipient exists.
  426. */
  427. void CheckRecipient(char *d)
  428.   {
  429.   char     sigChar;
  430.   if (!d[0])
  431.     {
  432.     sigChar = BAD_FORM;
  433.  
  434.     }
  435.   else if (strchr(d, '!') != NULL)
  436.   return ;  /* STadel routed mail - don't try to check it here */
  437.   else
  438.     {
  439.     if (PersonExists(d) != ERROR)
  440.     return ;
  441.     else
  442.     sigChar = NO_RECIPIENT;
  443.  
  444.     }
  445.   sendITLchar(sigChar);
  446.   mTrPrintf("%s", msgBuf.mbauth);
  447.   mTrPrintf("%s", d);
  448.   mTrPrintf("%s @ %s", msgBuf.mbdate, msgBuf.mbtime);
  449.  
  450.   }
  451. /*
  452. * doNetRooms()
  453. *
  454. * This function integrates temporary files containing incoming messages into
  455. * the data base.
  456. */
  457. void doNetRooms()
  458.   {
  459.   SYS_FILE fileNm;
  460.   int IntegrateRoom(SharedRoom *room, int system, int index, int roomslot,
  461.   void *d);
  462.   EachSharedRoom(thisNet, IntegrateRoom, NULL, NULL);
  463.   makeSysName(fileNm, RECOVERY_FILE, &cfg.netArea);
  464.   unlink(fileNm);
  465.  
  466.   }
  467. /*
  468. * IntegrateRoom()
  469. *
  470. * This function helps integrate incoming messages into a room.
  471. */
  472. int IntegrateRoom(SharedRoom *room, int system, int index, int roomslot,
  473. void *d)
  474.   {
  475.   if (chkNeedsProcessing(index))
  476.     {
  477.     ReadNetRoomFile(index, NULL);
  478.     resetNeedsProcessing(index);
  479.  
  480.     }
  481.   if (SR_Sent[index] == 1)
  482.   netBuf.netRooms[index].lastMess =  roomTab[roomslot].rtlastMessage;
  483.   return TRUE;
  484.  
  485.   }
  486. /*
  487. * ReadNetRoomFile()
  488. *
  489. * This function reads in a file of messages received on net.
  490. * NB: the passed parameter is the index into the netBuf.netRooms
  491. * pseudo-array, not the number of the room itself.  See the code.
  492. */
  493. void ReadNetRoomFile(int rover, char *fn)
  494.   {
  495.   label temp2;
  496.   if (cfg.BoolFlags.debug)splitF(netLog," ReadNetRoomFile(Rover:%d, fn:%s)\n",rover,(fn== NULL) ? "NULL":fn);
  497.   if (fn == NULL) sPrintf(temp2, netRoomTemplate, netRoomSlot(rover));
  498.   getRoom(netRoomSlot(rover));
  499.   if (roomBuf.rbShareType != PEON &&
  500.   GetMode(netBuf.netRooms[rover].mode) != PEON)
  501.   AssignAddress = NON_LOC_NET;
  502.   else
  503.   AssignAddress = LOC_NET;
  504.   InitVortexing();
  505.   AddNetMsgs((fn == NULL) ? temp2 : fn, inMail, TRUE, netRoomSlot(rover),
  506.   (fn == NULL));
  507.   FinVortexing();
  508.   AssignAddress = NULL;
  509.  
  510.   }
  511. /*
  512. * getMail()
  513. *
  514. * This function Grabs mail from caller.
  515. */
  516. void getMail()
  517.   {
  518.   SYS_FILE tempNm;
  519.   if( netDebug && logNetResults) splitF(netLog, "Receiving Mail\n");
  520.   makeSysName(tempNm, "tempmail.$$$", &cfg.netArea);
  521.   if (ITL_StartRecMsgs(tempNm, TRUE, TRUE, NULL) == ITL_SUCCESS)
  522.     {
  523.     processMail = TRUE;
  524.  
  525.     }
  526.  
  527.   }
  528. /*
  529. * reqSendFile()
  530. *
  531. * This function handles receiving a sent file.  Note that it handles file
  532. * redirection.
  533. */
  534. void reqSendFile(struct cmd_data *cmds)
  535.   {
  536.   long  proposed;
  537.   int count;
  538.   char work[100], work1[100], *Dir;
  539.   extern char *READ_ANY, *WRITE_ANY;
  540.   static char *Reject = "File %s from %s rejected because %s.";
  541.   /* don't accept files from rogues */
  542.   if (!PosId)
  543.     {
  544.     reply(BAD, "No room for file.");
  545.     return;
  546.  
  547.     }
  548.   /* handle incoming file redirection */
  549.   if ((Dir = RedirectFile(cmds->fields[0], netBuf.netName)) != NULL ||
  550.   (Dir = RedirectFile(cmds->fields[0], netBuf.nbShort)) != NULL)
  551.     {
  552.     RedirectName(work1, Dir, "mm12"); /* temp file name */
  553.     unlink(work1);  /* kill any prior backups (shouldn't be any ...) */
  554.     RedirectName(work, Dir, cmds->fields[0]);
  555.     if (access(work, 0) == 0)
  556.     rename(work, work1);
  557.  
  558.     }
  559.   else if (netSetNewArea(&cfg.receptArea))
  560.     {
  561.     proposed = atol(cmds->fields[2]);
  562.     if (sysRoomLeft() < proposed ||
  563.     proposed > ((long) cfg.maxFileSize) * 1024l)
  564.       {
  565.       reply(BAD, "No room for file.");
  566.       sPrintf(msgBuf.mbtext, Reject, cmds->fields[0], callerName,
  567.       proposed > ((long) cfg.maxFileSize) * 1024l ?
  568.       "the file was larger than #MAX_NET_FILE" :
  569.       "there was not enough room left in reception directory");
  570.       netResult(msgBuf.mbtext);
  571.       homeSpace();
  572.       return;
  573.  
  574.       }
  575.     count = 0;
  576.     strCpy(work, cmds->fields[0]);
  577.     while (access(work, 0) != -1)
  578.       {
  579.       sPrintf(work, "a.%d", count++);
  580.  
  581.       }
  582.  
  583.     }
  584.   else
  585.     {
  586.     reply(BAD, "System error");
  587.     return ;
  588.  
  589.     }
  590.   reply(GOOD, NULL);
  591.   if( logNetResults )splitF(netLog, "File Reception: %s\n", cmds->fields[0]);
  592.   ITL_Receive(work, FALSE, TRUE, putFLChar, fclose);
  593.   homeSpace();
  594.   if (haveCarrier)
  595.     {
  596.     if (strCmp(work, cmds->fields[0]) == SAMESTRING || Dir != NULL)
  597.     sPrintf(msgBuf.mbtext, "%s received from %s.", cmds->fields[0],
  598.     callerName);
  599.     else
  600.     sPrintf(msgBuf.mbtext, "%s (saved as %s) received from %s.",
  601.     cmds->fields[0], work, callerName);
  602.     netResult(msgBuf.mbtext);
  603.     if (Dir != NULL)  /* kill temporary bkp of redirected file */
  604.     unlink(work1);
  605.  
  606.     }
  607.   else if (Dir != NULL) /* failed transfer of redirected file */
  608.   rename(work1, work);
  609.  
  610.   }
  611. /*
  612. * netFileReq()
  613. *
  614. * This will handle requests for file transfers.
  615. */
  616. void netFileReq(struct cmd_data *cmds)
  617.   {
  618.   int  roomSlot;
  619.   extern char *READ_ANY;
  620.   if( logNetResults)splitF(netLog, "File request: %s in %s\n", cmds->fields[1],
  621.   cmds->fields[0]);
  622.   /* allow disabling this feature on a system by system basis */
  623.   if (PosId && netBuf.nbflags.NoDL)
  624.     {
  625.     reply(BAD, "Downloading disabled.");
  626.     return;
  627.  
  628.     }
  629.   if ((roomSlot = roomExists(cmds->fields[0])) == ERROR   ||
  630.   !roomTab[roomSlot].rtflags.ISDIR  ||
  631.   roomTab[roomSlot].rtflags.NO_NET_DOWNLOAD ||
  632.   !roomTab[roomSlot].rtflags.DOWNLOAD)
  633.     {
  634.     sPrintf(msgBuf.mbtext, "Room %s does not exist.", cmds->fields[0]);
  635.     reply(BAD, msgBuf.mbtext);
  636.     return;
  637.  
  638.     }
  639.   getRoom(roomSlot);
  640.   if (!setSpace(&roomBuf))
  641.     {
  642.     reply(BAD, "Directory error");
  643.     return;
  644.  
  645.     }
  646.   if (cmds->command == A_FILE_REQ)
  647.     {
  648.     reply(GOOD, "");
  649.     sPrintf(msgBuf.mbtext, "Following files sent to %s from %s: ",
  650.     callerName, roomBuf.rbname);
  651.     wildCard(netMultiSend, cmds->fields[1], FALSE, "", FALSE);
  652.     if (ITL_Send(STARTUP))
  653.       {
  654.       mTrPrintf("");
  655.       ITL_Send(FINISH);
  656.  
  657.       }
  658.  
  659.     }
  660.   else
  661.     {
  662.     if (access(cmds->fields[1], 4) == -1)
  663.       {
  664.       sPrintf(msgBuf.mbtext, "There is no '%s' in %s.", cmds->fields[1],
  665.       cmds->fields[0]);
  666.       reply(BAD, msgBuf.mbtext);
  667.       homeSpace();
  668.       return;
  669.  
  670.       }
  671.     reply(GOOD, "");
  672.     SendHostFile(cmds->fields[1]);
  673.     sPrintf(msgBuf.mbtext,
  674.     "%s downloaded from %s by %s.",
  675.     cmds->fields[1], formRoom(thisRoom, FALSE, FALSE), callerName);
  676.  
  677.     }
  678.   homeSpace();
  679.   netResult(msgBuf.mbtext);
  680.  
  681.   }
  682. /*
  683. * netRRReq()
  684. *
  685. * This function handles room sharing.  If SendBack is TRUE then this is a
  686. * room routing (LD) request and requires we send the room's current contents
  687. * back.
  688. */
  689. void netRRReq(struct cmd_data *cmds, char SendBack)
  690.   {
  691.   RoomSearch arg;
  692.   char reason[50];
  693.   strCpy(arg.Room, cmds->fields[0]);
  694.   if (!RoomRoutable(&arg))
  695.     {
  696.     sPrintf(reason, SharingRefusal[arg.reason], cmds->fields[0]);
  697.     if( logNetResults )splitF(netLog, "Refusing to share %s (%s)\n", cmds->fields[0], reason);
  698.     reply(BAD, reason);
  699.     return;
  700.  
  701.     }
  702.   if (!arg.virtual)
  703.     {
  704.     getRoom(arg.room);
  705.     recNetMessages(arg.index, arg.Room, arg.room, TRUE);
  706.     if (SendBack)
  707.     findAndSend(ERROR, R_SH_MARK, LOC_NET,
  708.     roomBuf.rbShareType == BACKBONE ? NON_LOC_NET : NULL, arg.index,
  709.     RoomSend, roomBuf.rbname, RoomReceive);
  710.  
  711.     }
  712.   else
  713.     {
  714.     RecVirtualRoom(arg.index, TRUE);
  715.     if (SendBack)
  716.     findAndSend(ERROR, NULL, NULL, NULL, arg.index, SendVirtual,
  717.     arg.Room, RecVirtualRoom);
  718.  
  719.     }
  720.  
  721.   }
  722. /*
  723. * recNetMessages()
  724. *
  725. * This function receives net messages.  This is not the same as processing
  726. * them.
  727. */
  728. void recNetMessages(int arraySlot, char *name, int slot, char ReplyFirst)
  729.   {
  730.   SYS_FILE fileNm, temp;
  731.   char reason[60];
  732.   if( logNetResults && netDebug )splitF(netLog, "Receiving %s\n", name);
  733.   sPrintf(temp, netRoomTemplate, slot);
  734.   makeSysName(fileNm, temp, &cfg.netArea);
  735.   switch (ITL_StartRecMsgs(fileNm, ReplyFirst, TRUE, NULL))
  736.     {
  737.     case ITL_SUCCESS:
  738.     setNeedsProcessing(arraySlot);
  739.     UpdateRecoveryFile(name);
  740.     break;
  741.     case ITL_NO_OPEN:
  742.     sPrintf(reason, "Internal error for %s", name);
  743.     reply(BAD, reason);
  744.     break;
  745.     case ITL_BAD_TRANS:
  746.     break;
  747.  
  748.     }
  749.  
  750.   }
  751. /*
  752. * UpdateRecoveryFile()
  753. *
  754. * This function updates the network recovery file.
  755. */
  756. void UpdateRecoveryFile(char *val)
  757.   {
  758.   SYS_FILE fileNm;
  759.   makeSysName(fileNm, RECOVERY_FILE, &cfg.netArea);
  760.   if (access(fileNm, 0) != 0)
  761.   CallMsg(fileNm, callerId);
  762.   CallMsg(fileNm, val);
  763.  
  764.   }
  765. /*
  766. * RoomRoutable()
  767. *
  768. * Is this room routable?
  769. */
  770. char RoomRoutable(RoomSearch *data)
  771.   {
  772.   if( netDebug && cfg.BoolFlags.debug )
  773.     {
  774.     splitF(netLog, "label Room(%s)  ", data->Room);     /* this is the target */
  775.     splitF(netLog, "char  virtual(%x)",data->virtual);  /* is virtual? */
  776.     splitF(netLog, "int   room(%d)",   data->room);     /* room slot */
  777.     splitF(netLog, "int   index(%d)",  data->index);
  778.     splitF(netLog, "char  reason(%x)", data->reason);
  779.     };
  780.   if (!PosId)
  781.     {
  782.     if( logNetResults && netDebug )splitF(netLog, "-No Password.-");
  783.     data->reason = NO_PWD;
  784.     return FALSE;
  785.  
  786.     }
  787.   if (callSlot == ERROR)
  788.     {
  789.     if( logNetResults && netDebug )splitF(netLog, "-Not sharing.-");
  790.     data->reason = NOT_SHARING;
  791.     return FALSE;
  792.  
  793.     }
  794.   data->reason = NO_ROOM;
  795.   data->virtual = FALSE;
  796.   EachSharedRoom(thisNet, IsRoomRoutable, VirtRoomRoutable, data);
  797.   return (char)(data->reason == FOUND);
  798.  
  799.   }
  800. /*
  801. * IsRoomRoutable()
  802. *
  803. * This function checks to see if the given shared room matches with the
  804. * argument presented in the void pointer parameter.
  805. */
  806. int IsRoomRoutable(SharedRoom *room, int system, int index, int roomslot,
  807. void *d)
  808.   {
  809.   RoomSearch *arg;
  810.   arg = d;
  811.   if (strCmpU(roomTab[roomslot].rtname, arg->Room) == SAMESTRING)
  812.     {
  813.     if (roomTab[roomslot].rtflags.SHARED == 0)
  814.     arg->reason = NOT_SHARING;
  815.     else
  816.     arg->reason = FOUND;
  817.     arg->room = roomslot;
  818.     arg->index = index;
  819.     return ERROR;   /* stop searching */
  820.  
  821.     }
  822.   return TRUE;
  823.  
  824.   }
  825. /*
  826. * netMultiSend()
  827. *
  828. * This function will send requested files via the net.
  829. */
  830. void netMultiSend(DirEntry *fn)
  831.   {
  832.   long Sectors;
  833.   if (!gotCarrier()) return ;
  834.   strCat(msgBuf.mbtext, fn->unambig);
  835.   strCat(msgBuf.mbtext, " ");
  836.   Sectors     = ((fn->FileSize + 127) / SECTSIZE);
  837.   if (ITL_Send(STARTUP))
  838.     {
  839.     mTrPrintf("%s", fn->unambig);
  840.     mTrPrintf("%ld", Sectors);
  841.     ITL_Send(FINISH);
  842.  
  843.     }
  844.   SendHostFile(fn->unambig);
  845.  
  846.   }
  847. /*
  848. * RecoverNetwork()
  849. *
  850. * This function is called during system startup.  If a disaster hit during
  851. * a network session, this will try to recover messages already transferred
  852. * from files left in the network directory.
  853. */
  854. void RecoverNetwork()
  855.   {
  856.   SYS_FILE fileNm;
  857.   char line[50];
  858.   label temp;
  859.   int rover;
  860.   FILE *fd;
  861.   RoomSearch arg;
  862.   extern char inNet;
  863.   makeSysName(fileNm, RECOVERY_FILE, &cfg.netArea);
  864.   if ((fd = safeopen(fileNm, READ_TEXT)) == NULL)
  865.   return;   /* normal */
  866.   inNet = NORMAL_NET;
  867.   SpecialMessage("Network Cleanup");
  868.   if (GetAString(line, sizeof line, fd) != NULL)
  869.     {
  870.     if (searchNet(line, &netBuf) != ERROR)
  871.       {
  872.       PosId = TRUE;
  873.       while (GetAString(line, sizeof line, fd) != NULL)
  874.         {
  875.         if (strncmp(line, FAST_TRANS_FILE, strLen(FAST_TRANS_FILE))
  876.         == SAMESTRING)
  877.         RecoverMassTransfer(line);
  878.         else
  879.           {
  880.           strCpy(arg.Room, line);
  881.           if (RoomRoutable(&arg) && !arg.virtual)
  882.             {
  883.             printf("%s\n", line);
  884.             ReadNetRoomFile(arg.index, NULL);
  885.  
  886.             }
  887.  
  888.           }
  889.  
  890.         }
  891.       readNegMail(FALSE);
  892.       AddNetMsgs("tempmail.$$$", inMail, 2, MAILROOM, TRUE);
  893.       for (rover = 0; ; rover++)
  894.         {
  895.         sPrintf(temp, "rmail.%d", rover);
  896.         if (AddNetMsgs(temp, inRouteMail, 2, MAILROOM, TRUE) == ERROR)
  897.         break;
  898.  
  899.         }
  900.  
  901.       }
  902.  
  903.     }
  904.   fclose(fd);
  905.   unlink(fileNm);
  906.   inNet = NON_NET;
  907.  
  908.   }
  909.